# -*- coding:utf-8 -*-
"""
Author：Administrator
Date:2021年10月28日
"""
import re

# 1.用户名匹配
# a.用户名只能包含数字字母和下划线
# b.不能以数字开头
# c.长度在6到16位范围内

# username = input('请输入用户名:')
# result = re.fullmatch(r'^[a-zA-Z_][a-zA-Z0-9_]{5,15}', username)
# if result is None:
# 	print('输入的用户名不合法')
# else:
# 	print(username+'是一个合法的用户名')


# 2.判断密码
# a.不能包括!@#$%^&*这些特殊符号
# b.必须以字母开头
# c.长度在6到12位范围内

# password = input('请输入密码:')
# if re.fullmatch(r'[a-zA-z][^!@#$%^&*]{5,11}',password) is None:
# 	print('密码不合法')

# 3.提取邮箱与手机号
# with open('test.txt', 'r',encoding='utf8') as f:
# 	lines = f.readlines()
# 	for line in lines:
# 		# print(line, end='')
# 		x = re.findall(r'.+(\d{11}).+?(\w+@\w+\.com)', line)
# 		print(x)

# 4.提取用户输入数据中的数值(数值包括正负数还包括整数和小数在内)并求和
# content = input('请输入一段内容:') # -3.14good87.5nice19bye
# x = re.finditer(r'-?\d+(\.\d+)?', content)
# for i in x:
# 	print(i.group())
# result = re.findall(r'-?\d+(?:\.\d+)?', content)
# x = '+'.join(result)
# print(x)
# print(eval(x))

# 5. 提取http://www.codingfans.cc/show/tom/22
# url = "http://www.codingfans.cc/show/tom/22"
# z = re.search(r'[^:/](/.+/?)', url)
# print(z.group(1))

# 6. 匹配ipv4地址
# 0-255 正则规则
ip = input('请输入一个IP地址：')
#          0-9 10-99  100-199 200-249 250-255
pattern = r'((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])'
if re.fullmatch(pattern, ip) is None:
	print('不匹配')
else:
	print('匹配')


# number = ip.split('.')
#
# if len(number) !=4:
# 	print('不合法')
# else:
# 	flag = True
# 	for i in number:
# 		if i == 0 or (0<=int(i)<=255 and not number.startswith('0')):
# 			pass
# 		else:
# 			flag =False
# 			break
# 	if not flag:
# 		print('不合法')
# 	else:
# 		print('合法')
